<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/lib/bootstrap-3.3.7-dist/css/bootstrap.css" />

<style 	type="text/css">
	.login{
		margin-left:800px;
	}
</style>
</head>
<body>
<body>
	<form method="post" onsubmit="return false">
		名字：<input id="searchId" type="text" name=searchName /> 
		<input type="button" onclick="search()" value="搜索"  class="btn btn-success" />
	</form>
	
	<a onclick="insert()" class="btn btn-info">添加</a>
	
	<a href="javascript:void(0)" onclick="userList()" class="btn btn-success">在线用户列表</a>
	
	<span class="login">
		欢迎回来:<a>${admin.name}</a>&nbsp;&nbsp;&nbsp;
			<a href="javascript:void(0)" onclick="logout()" class="btn btn-info">注销</a>
	</span>
	
	<%-- 	${list} --%>
	<table class="table  table-striped table-bordered table-hover table-condensed">
		<tr>
			<td>编号</td>
			<td>姓名</td>
			<td>密码</td>
			<td>邮箱</td>
			<td>职务</td>
			<td>部门</td>
			<td>年龄</td>
			<td>删除</td>
			<td>修改</td>
		</tr>
		<c:forEach items="${pageBean.list}" var="user">
			<tr>
				<td>${user.id}</td>
				<td>${user.name}</td>
				<td>${user.password}</td>
				<td>${user.email}</td>
				<td>${user.role.name}</td>
				<td>${user.department.name}</td>
				<td>${user.age}</td>
				<td><a href="javascript:void(0)" onclick="deleteById(${user.id})" class="btn btn-danger">删除</a></td>
				<td><a href="javascript:void(0)" onclick="updateById(${user.id})"  class="btn btn-warning">修改</a></td>
			</tr>
		</c:forEach>
	</table>
	<nav aria-label="Page navigation">
		<ul class="pagination">
			<c:if test="${pageBean.pageNo==1 }">
				<li class="disabled">
					<a href="#" aria-label="Previous"> 
					<span aria-hidden="true">&laquo;</span>
					</a>
				</li>
			</c:if>
			<c:if test="${pageBean.pageNo!=1 }">
				<li>
					<a href="${pageContext.request.contextPath}/user/pageList.action?pageNo=${pageBean.pageNo-1}" aria-label="Previous"> 
					<span aria-hidden="true">&laquo;</span>
					</a>
				</li>
			</c:if>
			<!-- 翻页高亮 -->
			<c:forEach begin="1" end="${pageBean.totalPage}" var="i">
				<c:if test="${pageBean.pageNo==i}">
					<li class="active"><a href="#">${i}</a></li>
				</c:if>
				<c:if test="${pageBean.pageNo!=i}">
					<li><a href="${pageContext.request.contextPath}/user/pageList.action?pageNo=${i}&pageSize=3">${i}</a></li>
				</c:if>
			</c:forEach>
			
			<c:if test="${pageBean.pageNo==pageBean.totalPage}">
				<li class="disabled">
					<a href="#" aria-label="Next"> 
					<span aria-hidden="true">&raquo;</span>
					</a>
				</li>
			</c:if>
			<c:if test="${pageBean.pageNo!=pageBean.totalPage}">
				<li>
					<a href="${pageContext.request.contextPath}/user/pageList.action?pageNo=${pageBean.pageNo+1}" aria-label="Next"> 
					<span aria-hidden="true">&raquo;</span>
					</a>
				</li>
			</c:if>
		</ul>
	</nav>
	
	<script src="../js/jquery-1.11.3.js" type="text/javascript" charset="utf-8"></script>
	<script src="../lib/layer/layer.js" type="text/javascript" charset="utf-8"></script>
	<script src="../lib/mylayer.js" type="text/javascript" charset="utf-8"></script>
	<script src="../lib/util.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		function search(searchName){
			layer.open({
				type:2,
				title:"搜索用户",
				content:"${pageContext.request.contextPath}/user?method=search&searchName=" + searchName,
				skin: 'layui-layer-molv',
				area:["50%","50%"]
			})
		}
		
		function deleteById(id){
			layer.confirm(
					"你确定要删除么？",
					{icon:3,title:"删除"},
					function(index){
						$.post(
						 	"${pageContext.request.contextPath}/user?method=deleteById&id=" + id,
						 	function(jsonObj){
						 		if(jsonObj.code == util.SUCCESS){
						 			mylayer.successMsg(jsonObj.msg);
						 			location.reload();
						 		} else{
						 			mylayer.errorMsg(jsonObj.msg);
						 		}
						 	},
						 	"json"
						);
					}
			);
		}
		
		function updateById(id){
			layer.open({
				type:2,
				title:"信息修改",
				content:"${pageContext.request.contextPath}/user?method=toUpdate&id=" + id,
				skin: 'layui-layer-molv',
				area:["50%","50%"]
			});
	  }
		
		function insert(){
			layer.open({
				type:2,
				title:"添加用户",
				content:"${pageContext.request.contextPath}/user_insert.jsp",
				skin: 'layui-layer-molv',
				area:["50%","50%"]
			});
		}
		
		function logout(){
			layer.confirm(
				"你确定要注销么？",
				{icon:3,title:"注销"},
				function(index){
					location.href="${pageContext.request.contextPath}/loginController/logout.action";
					layer.close(index);
				}
			)
		}
		
		function userList(){
			layer.open({
				type:2,
				title:"在线用户",
				content:"${pageContext.request.contextPath}/online_user_list.jsp",
				skin: 'layui-layer-molv',
				area:["60%","60%"]
			});
		}
	</script>

</body>
</html>